package com.jy.rhin.support.notification.client;

import com.jy.rhin.config.ws.WsClientFactory;
import com.jy.rhin.facade.ws.basic.notification.NotificationConsumer;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessageDto;
import com.jy.rhin.support.notification.NotificationConvertFactory;
import com.jy.rhin.support.notification.convertor.BaseNotificationConverter;
import org.oasis_open.docs.wsn.b_2.Notify;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: webService调用客户端
 * @Author: lww
 * @Date: 2022/7/29 9:34
 */
@Service("SOAP")
public class NotificationClientSoapImpl implements NotificationClient {

    @Resource
    WsClientFactory wsClientFactory;

    @Resource
    NotificationConvertFactory notificationConvertFactory;


    @Override
    public void notify(PublishMessageDto publishMessage) {
        //封装webService参数
        String topicExp = publishMessage.getTopicExp();
        //获取对应的消息转换器转换消息
        BaseNotificationConverter convert = notificationConvertFactory.getConvert(topicExp);
        Notify notify = convert.convertMessage(publishMessage);
        //创建webService-Client，调用订阅者通知接口
        NotificationConsumer notificationClient = wsClientFactory.getNotificationClient(publishMessage.getAddressUrl());
        notificationClient.notify(notify);
    }
}
